<?php
  define('ACC', true); 
  require('./include/init.php'); 
  session_start();
  $userid = $_SESSION['user_id']; 
  $companyname = $_POST['company_name'];

  //$companyname = '格勒山神';
  //$userid = '3';
  //echo '<head><meta charset = "utf-8"></head>';
  //print_r($_SESSION);
  //include(ROOT . 'view/create_company.html');
  $company = new companymodel();
  $user = new usermodel();
  if ($user->numofcompany($userid)>0){
      $msg = '你已经有公司了，创建公司失败！'; 
  }else{
      $companyinfo = $company->creatcompany($userid, $companyname);
      if($companyinfo == false){          
        $msg = '创建公司失败，请检查初始公司状态！';
      }else{ 
        $msg = '你创建了一家公司，公司名称为:' . $companyinfo['company_name'] . '，公司类型为:' . $companyinfo['company_category'] . '。';
      }
  }
  
  /*
  
  
  $companyid = $company->creatcompany($userid, $companyname);
  if($companyid){
      $msg = '你已经创建了一家公司，公司名称为:' . $companyname . '，公司ID为:' . $companyid . '。';  
  }else{
      $msg = '创建公司失败！'; 
  }
  
  */
  include(ROOT . 'view/msg.html');
  
  
  
  /*
  $rawmaterial = array('element_id'=>1003, 'company_id' => '4', 'element_value'=>1000000.00, 'raw_material_trans'=>2);
  print_r($company->insertelement('raw_material', $rawmaterial));   
  */
  ?>
